package org.compiere.model;

import java.util.Properties;

import org.compiere.apps.IProcessParameter;
import org.compiere.apps.ProcessCtl;
import org.compiere.apps.ProcessParameterPanel;
import org.compiere.process.ProcessInfo;
import org.compiere.util.ASyncProcess;
import org.compiere.util.DB;

public class Mcmsagreementline extends X_cms_agreement_line implements  ASyncProcess{

	/**
	 * 
	 */
	private static final long serialVersionUID = 2056823124740558297L;

	public Mcmsagreementline(Properties ctx, int cms_agreement_line_ID,
			String trxName) {
		super(ctx, cms_agreement_line_ID, trxName);
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * 	After Save
	 *	@param newRecord new
	 *	@param success success
	 *	@return success
	 */
	protected boolean afterSave (boolean newRecord, boolean success)
	{
		boolean isSigned = this.isSign_N();
		
		if(isSigned)
		{
			int ad_process_id = getProcess();
			ProcessInfo pi = new ProcessInfo("Agreement Not Approved", ad_process_id, this.get_Table_ID(), this.get_ID());
			//pi.setAD_Client_ID(this.getAD_Client_ID());
			//pi.setAD_User_ID(this.getAD);
			
			ProcessParameterPanel pu = new ProcessParameterPanel(0, pi);
			ProcessCtl.process(this, 0, (IProcessParameter) pu, pi, null);
		}
//		Env.reset(false);
		return success;
	}	//	afterSave

	private int getProcess()
	{
		String sql = "SELECT AD_Process_ID FROM AD_Process WHERE LOWER(Name) LIKE '%cms_agreementnotapproved%'";
		
		int ad_process_id = DB.getSQLValue(get_TrxName(), sql);
		
		return ad_process_id;
	}
	
	@Override
	public void lockUI(ProcessInfo pi) {}

	@Override
	public void unlockUI(ProcessInfo pi) {}

	@Override
	public boolean isUILocked() {
		return false;
	}

	@Override
	public void executeASync(ProcessInfo pi) {}
}
